class Spawner:
    def __init__(self, spawner, perSpawn, ticsPerSpawn):
        self.spawner = spawner
        self.perSpawn = perSpawn
        self.ticsPerSpawn = ticsPerSpawn
        self.reset()
    def reset(self):
        self.timer = 0
    def spawn(self):
        self.timer += 1
        if self.timer >= int(self.ticsPerSpawn()):#200-kills
            for i in range(0,int(self.perSpawn())): #kills/10+1
                self.spawner()
                self.timer = 0
class Function:
    def __init__(self, x):
        self.x = x
    def calculate(self):
        return self.x()

    
class Linear(Function):
    def __init__(self, x, slope, intercept):
        Function.__init__(self, x)
        self.slope = slope
        self.intercept = intercept
    def calculate(self):
        return ( ( self.slope * self.x() ) + self.intercept )
    
    
class MinBounded(Function):
    def __init__(self, x, minimum):
        Function.__init__(self, x)
        self.minimum = minimum
    def calculate(self):
        x = self.x()
        if x < self.minimum: x = minimum
        return x


class KillBasedSpawner(Spawner):
    def __init__(self, spawner, kills):
        ps_function = Linear(kills, .1, 1)
        perSpawn = ps_function.calculate
        tps_function = Linear(kills, -1, 200)
        tps_function = MinBounded(tps_function.calculate, 1)
        ticsPerSpawn = tps_function.calculate
        Spawner.__init__(self, spawner, perSpawn, ticsPerSpawn)
#/sal2
